/*
 * @Author: FanWeiHua
 * @Date: 2021-07-08 10:44:21
 * @LastEditTime: 2021-07-14 09:56:41
 * @Description: 路由入口
 */
'use strict';
import React from 'react';
import { Switch } from 'react-router';
import { BrowserRouter, HashRouter } from 'react-router-dom';
import renderRoutes from './renderRoutes';
import asyncComponent from '@/common/tool/asyncComponent'; // 异步加载
import router from './router'; // 路由
// 首页路由
const indexRoute = {
  name: '首页',
  path: '/',
  exact: true,
  component: asyncComponent(() => import('../container/index/index'))
};
const routes = [indexRoute, ...router]; // 路由 合并
const RouterComponent = () => <Switch>{renderRoutes(routes)}</Switch>;
const RootRouter = () => {
  if (webpackConfig.nodeEnv === 'local') {
    return (
      <HashRouter>
        <RouterComponent />
      </HashRouter>
    );
  } else {
    return (
      <BrowserRouter basename={webpackConfig.publicPath || '/'}>
        <RouterComponent />
      </BrowserRouter>
    );
  }
};
export default RootRouter;
